package com.vegetable.modules.service.stock;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.modules.entity.baseData.Products;
import com.vegetable.modules.entity.inbound.AgentDeliveryDetailPack;
import com.vegetable.modules.entity.stock.Stock;
import com.vegetable.modules.entity.stock.po.StockQueryPO;
import com.vegetable.modules.entity.stock.po.StockUpdatePO;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 库存表 服务类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-21
 */
public interface IStockService extends IService<Stock> {

    /**
     * 库存列表查询
     * @param po
     * @return
     */
    PageUtils queryPage(StockQueryPO po);

    /**
     * 查询分组商品库存列表
     * @param params
     * @return
     */
    PageUtils stockGroupBy(Map<String, Object> params);

    /**
     * 查询某商品的库存列表
     * @param commodityId
     * @return
     */
    List<Stock> stockList(Long commodityId);

    List<Stock> stockList(List<Long> commodityIds);

    /**
     * 查询商品库存
     * @param po
     * @return
     */
    IPage<Stock> stockList(StockQueryPO po);

    /**
     * 更新商品库存
     * @param po
     * @return
     */
    Integer updateStock(StockUpdatePO po) throws Exception;

    void updatePackageUnitPriceByDetailId(List<AgentDeliveryDetailPack> array, Long detailId, Long orderId) throws Exception;

    void updateStockByDetailId(BigDecimal priceDifference, Long detailId, Long orderId, BigDecimal goodsUnitPrice) throws Exception;

    /**
     *
     * @param orderTime 订单时间
     * @param priceUnit 单价
     * @param product 产品信息
     * @param specsId 规格ID
     * @param specsName 规格名称
     * @param inNumber 入库数量
     * @param inWeight 入库重量
     * @param storageType 入库类型
     * @param warehouseId 仓库id
     * @param warehouseName 仓库名称
     * @param agentName 代办名
     * @param packageCost 包装价格信息
     * @param storageOrderNo 入库单据编号
     * @param orderId 订单ID
     * @param detailId 详情ID
     * @param unitGoodsPrice 蔬菜单价
     */
    void  inStock(Date orderTime, BigDecimal priceUnit, Products product, Long specsId, String specsName, Integer inNumber, BigDecimal inWeight, Integer storageType , Long warehouseId, String warehouseName, String agentName, String packageCost, String storageOrderNo, Long orderId, Long detailId, BigDecimal unitGoodsPrice);

    @Deprecated
    void saveOutStock(BigDecimal price_unit, int outNumber, BigDecimal outWeight, Long stockId) throws Exception;

    /**
     * 查询某条入库单的所有库存信息
     * @param docNo
     * @return
     */
    List<Stock> queryStock(String docNo);

    List<Stock> queryStockByOrderId(Long orderId);

    List<Stock> queryStockByDetailId(Long detailId);

    List<Stock> queryStockByDetailIdAndOrderId(Long orderId, Long detailId);

    Stock queryStockByDetailIdAndOrderIdAndWarehouseId(Long orderId, Long detailId, Long warehouseId);

    List<Stock> queryDetailStock(Long id, boolean accurate, String commodityName, BigDecimal standard);

    List<Stock> getStocks(boolean accurate, String commodityName, BigDecimal standard, Long commodityId, Long specsId);

    Stock selectById(Long stockId);

    int deleteById(Long stockId);

    /**
     * 根据商品id 规格id查询库存列表
     * @param commodityId
     * @param specsId
     * @return
     */
    List<Stock> selectGoodsStock(Long commodityId, Long specsId);

    List<Stock> selectGoodsStock(List<Long> commodityId);

    List<Stock> selectGoodsStock(Long commodityId, Long specsId, String agentName);

    List<Stock> selectStockByIds(List<Long> stockIds);

    void releaseStockByDetailId(Long detailId) throws Exception;

    void releaseStockByDetailId(Long orderId, Long detailId, Integer orderType) throws Exception;

    void releaseStockByDetailId2(Long detailId) throws Exception;

    Map<Integer, BigDecimal> releaseStock(Stock stock) throws Exception;

    void releaseStock(Long orderId, Long detailId, Long warehouseId) throws Exception;

    void releaseStock(Long orderId, Long detailId, Long warehouseId, boolean isDEl) throws Exception;

    void releaseStock(String storageOrderNo);

    /**
     * 查询订单时间超过两天的成品库存
     * @return 成品库存列表
     */
    List<Stock> getFinishedProductsWithOldOrderTime();
    /**
     * 根据多种条件分页查询订单时间超过两天的成品库存
     * @param po 查询条件
     * @return 分页结果
     */
    PageUtils getFinishedProductsWithOldOrderTimeByConditionsPage(StockQueryPO po);
    
    /**
     * 根据基础批次号查找相关库存记录
     * @param baseBatchNo 基础批次号
     * @return 相关库存记录列表
     */
    List<Stock> findStocksByBaseBatchNo(String baseBatchNo);

    /**
     * 查询非零库存列表（关联商品分类信息）
     * @param page 分页对象
     * @param params 查询参数
     * @return 库存列表
     */
    IPage<Stock> getNonZeroStockWithCategory(IPage<Stock> page, Map<String, Object> params);
    
}